
const Koa = require('koa');
const app = new Koa();

app.use(async(ctx) => {

    if (ctx.url === '/index'){
        ctx.cookies.set(
            'MyName'
            ,'JSPang'
            ,{
                domain : 'localhost',
                path : '/index',
                //保存时间-1小时
                maxAge : 1000 * 60 *60*24*360,
                //过期时间
                expires : new Date('2018-12-05'),
                //
                httpOnly:false,
                //不允许重写
                overwrite:false
            }
        );
        ctx.body = 'cookie is ok!';
      

    }else{

        if( ctx.cookies.get('MyName')){
            ctx.body = ctx.cookies.get('MyName');
        }else{
            ctx.body = 'Cookie is none';
        }
    

        
    }
})


app.listen(3000,() =>{
     
    console.log('[demo] server is starting at port 3000!');
    
})